<template>
	<view>
		<Header
			:title="t('plan.create.title')"
			:showRight="true"
			:titleSize="14"
			:Righttext="t('save')"
			:rightColor="rightColor"
			:rightSize="14"
			@rightClick="saveAddFun" />
		<addTaskContentVue
			ref="addRef"
			:device_sn="device_sn"
			:mapUrl="mapUrl"
			@isSave="isSaveFun" />
	</view>
</template>

<script setup lang="ts">
import Header from "@/components/header/index.vue";
import { onMounted, ref, getCurrentInstance } from "vue";
import addTaskContentVue from "./components/addTaskContent.vue";
import { onLoad } from "@dcloudio/uni-app";
import { useI18n } from "vue-i18n";
const { t } = useI18n();
const rightColor = ref("#999");
const device_sn = ref("");
const mapUrl = ref("");
const addRef = ref<{
	saveFun: (type: number) => Promise<boolean>;
}>();

onLoad((options) => {
	if (options?.device_sn) {
		device_sn.value = options.device_sn;
	}
	const mapStore = useUniversalStorage<string>("Map_Store", null);
	mapUrl.value = mapStore.value.map_info.map_docs[0].oss_url || "";
});
const isSaveFun = (val: boolean) => {
	if (val) {
		rightColor.value = "#0084fc";
	} else {
		rightColor.value = "#999";
	}
};
const saveAddFun = async () => {
	if (!addRef.value || rightColor.value !== "#0084fc") return;
	await addRef.value.saveFun(1);
};
</script>

<style lang="scss" scoped></style>
